home *** CD-ROM | disk | FTP | other *** search
/ 3D Images / 3D Images.iso / programs / amiga / rayshade / libshade / stats.c < prev    next >
C/C++ Source or Header  |  1995-01-12  |  4KB  |  151 lines

  1. /*
  2.  * stats.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * stats.c,v 4.1 1994/08/09 08:05:00 explorer Exp
  17.  *
  18.  * stats.c,v
  19.  * Revision 4.1  1994/08/09  08:05:00  explorer
  20.  * Bump version to 4.1
  21.  *
  22.  * Revision 1.1.1.1  1994/08/08  04:52:18  explorer
  23.  * Initial import.  This is a prerelease of 4.0.6enh3, or 4.1 possibly.
  24.  *
  25.  * Revision 4.0  91/07/17  14:47:41  kolb
  26.  * Initial version.
  27.  * 
  28.  */
  29. #include <ctype.h>
  30. #include "rayshade.h"
  31. #include "options.h"
  32. #include "stats.h"
  33.  
  34. RSStats Stats;            /* Statistical information */
  35. Geom *GeomRep = NULL;    /* Linked list of object representatives */
  36.  
  37. static void PrintGeomStats();
  38.  
  39. void
  40. StatsPrint()
  41. {
  42.     extern void PrintMemoryStats();
  43.     unsigned long TotalRays;
  44.  
  45. #ifndef LINDA
  46.     RSGetCpuTime(&Stats.Utime, &Stats.Stime);
  47. #endif
  48.     ShadowStats(&Stats.ShadowRays, &Stats.ShadowHits,
  49.             &Stats.CacheHits, &Stats.CacheMisses);
  50.     IntersectStats(&Stats.BVTests);
  51.     
  52.     TotalRays = Stats.EyeRays + Stats.ShadowRays + Stats.ReflectRays
  53.              + Stats.RefractRays;
  54.     Stats.ShadowHits += Stats.CacheHits;
  55.     Stats.HitRays += Stats.ShadowHits;
  56. #ifdef LINDA
  57.     fprintf(Stats.fstats,"Workers:\t\t\t%d\n",Options.workers);
  58. #endif
  59.     fprintf(Stats.fstats,"Eye rays:\t\t\t%lu\n", Stats.EyeRays);
  60.     fprintf(Stats.fstats,"Shadow rays:\t\t\t%lu\n",Stats.ShadowRays);
  61.     fprintf(Stats.fstats,"Reflected rays:\t\t\t%lu\n",Stats.ReflectRays);
  62.     fprintf(Stats.fstats,"Refracted rays:\t\t\t%lu\n",Stats.RefractRays);
  63.     fprintf(Stats.fstats,"Total rays:\t\t\t%lu\n", TotalRays);
  64.     if (TotalRays != 0)
  65.         fprintf(Stats.fstats,"Intersecting rays:\t\t%lu (%3.3f%%)\n",
  66.             Stats.HitRays,
  67.             100. * (float)Stats.HitRays / (float)TotalRays);
  68.     if (Stats.ShadowRays != 0) {
  69.         if (Options.cache)
  70.             fprintf(Stats.fstats,
  71.                 "Shadow cache hits:\t\t%lu (%lu misses)\n",
  72.                 Stats.CacheHits, Stats.CacheMisses);
  73.         fprintf(Stats.fstats,"Total shadow hits:\t\t%lu (%3.3f%%)\n",
  74.             Stats.ShadowHits, 100.*(float)Stats.ShadowHits /
  75.             (float)Stats.ShadowRays);
  76.     }
  77.     fprintf(Stats.fstats,"Supersampled pixels:\t\t%lu\n",
  78.         Stats.SuperSampled);
  79.     fprintf(Stats.fstats,"B.V. intersection tests:\t%lu\n",Stats.BVTests);
  80.     PrintGeomStats();
  81. #ifdef LINDA
  82.     fprintf(Stats.fstats,"Average CPU time/processor:\t");
  83. #else
  84.     fprintf(Stats.fstats,"Total CPU time (sec):\t\t");
  85. #endif
  86.     fprintf(Stats.fstats,"%2.2f (%2.2fu + %2.2fs)\n",
  87.         Stats.Utime+Stats.Stime, Stats.Utime, Stats.Stime);
  88.     if (TotalRays != 0.)
  89.         fprintf(Stats.fstats,"Seconds / ray:\t\t\t%4.4f\n",
  90.             (Stats.Utime + Stats.Stime) / (Float)TotalRays);
  91.     if (Stats.HitRays != 0.)
  92.         fprintf(Stats.fstats,"Seconds / intersecting ray:\t%4.4f\n",
  93.             (Stats.Utime + Stats.Stime)/(Float)Stats.HitRays);
  94.     PrintMemoryStats(Stats.fstats);
  95.     if (Options.zbufprint)
  96.         ZbufPrint();
  97. }
  98.  
  99. static void
  100. PrintGeomStats()
  101. {
  102.     Geom *otmp;
  103.     unsigned long tests, hits, totaltests, totalhits;
  104.     char *name;
  105.     extern void GeomStats();
  106.  
  107.     totaltests = totalhits = 0;
  108.  
  109.     for (otmp = GeomRep; otmp; otmp = otmp->next) {
  110.         GeomStats(otmp, &tests, &hits);
  111.         if (tests <= 0)
  112.             continue;
  113.         name = GeomName(otmp);
  114.         fprintf(Stats.fstats,
  115.             "%c%s intersection tests:\t%lu (%lu hit, %f%%)\n",
  116.                 toupper((int)name[0]), &name[1], tests, hits,
  117.                 100.*(float)hits/(float)tests);
  118.         if (!IsAggregate(otmp)) {
  119.             totaltests += tests;
  120.             totalhits += hits;
  121.         }
  122.     }
  123.     fprintf(Stats.fstats,"Total prim. intersection tests:\t%lu",
  124.         totaltests);
  125.     if (totaltests == 0)
  126.         fprintf(Stats.fstats,"\n");
  127.     else
  128.         fprintf(Stats.fstats," (%lu hit, %f%%)\n", totalhits,
  129.             100.*(float)totalhits/(float)totaltests);
  130. }
  131.  
  132. void
  133. StatsAddRep(obj)
  134. Geom *obj;
  135. {
  136.     Geom *otmp;
  137.  
  138.     for (otmp = GeomRep; otmp; otmp = otmp->next) {
  139.         if (otmp->methods->stats == obj->methods->stats)
  140.             return;
  141.     }
  142.  
  143.     /*
  144.      * Stats method didn't match anything found so far.  Add
  145.      * a copy of obj to head of GeomRep list.
  146.      */
  147.     otmp = GeomCopy(obj);
  148.     otmp->next = GeomRep;
  149.     GeomRep = otmp;
  150. }
  151.